<template>
  <div class="_wz_cent_main _wz_place">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="运输企业">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="地点类型">
          <i-select v-model.number="formDataSearch.placeType" filterable placeholder="请选择地点类型" clearable>
            <Option :value="1">起运地</Option>
            <Option :value="2">目的地</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="addTableData">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <Drawer v-model="basicType" :title="formTitle" :draggable="true" width="700px" :mask-closable="false">
      <placeAdd v-if="basicType" :selectData="selectData" @closeFun="closeFun"></placeAdd>
    </Drawer>
  </div>
</template>
<script>
  import placeAdd from "./placeAdd";
  import wzTbale from "../../../components/table/table";

  export default {
    components: {
      placeAdd,//添加
      wzTbale,//列表
    },
    data() {
      return {
        subDeptList: [],//运输企业
        basicType: false,
        formTitle: '',
        selectData: {},
        formDataSearch: {},//搜索表单数据
        tableData: {
          url: this.apiUrl.billBasicBillBasicPlacePageList,//请求地址
          method: 'post',//请求方式
          where: {},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {
              title: '地点类型', minWidth: 140, render: (h, params) => {
                if (params.row.placeType == 1) {
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '起运地')
                } else {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '目的地')
                }
              }
            },
            {title: '地点名称', key: 'placeName', minWidth: 200},
            {title: '地址详情', key: 'placeAddress', minWidth: 200},
            {title: '行政区域',minWidth: 200,
              render: (h, params) => {
                return h('span', params.row.placeProvinceName + ' '+ params.row.placeCityName+ ' '+params.row.placeCountyName);
              }
            },
            {title: '运输企业', key: 'deptName', minWidth: 200},
            {title: '创建时间', key: 'createTime', minWidth: 170},
            {
              title: '操作', fixed: 'right', width: 120,
              render: (h, params) => {
                let operationButtons = [];

                operationButtons.push(h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.formTitle = '修改';
                      this.basicType = true;
                    }
                  }
                }, '修改'))


                if (operationButtons.length > 0) {
                  operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                }
                operationButtons.push(h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      var that = this;
                      that.$Modal.confirm({
                        title: '删除提醒',
                        content: '确定要删除该条记录吗？',
                        onOk: () => {
                          that.axios.post(that.apiUrl.billBasicBillBasicPlaceDelete,{uuid:params.row.uuid}).then(res => {
                            if (res) {
                              that.$Message.success('删除成功')
                              that.$refs.wzTbale.tableLoadData();
                            }
                          }).catch(err => {
                            console.log("失败", err)
                          })
                        }
                      })
                    }
                  }
                }, '删除'))

                return operationButtons;
              }
            }
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },

      }
    },
    computed: {//计算属性

    },
    mounted() {//mounted 挂载结束状态
      var that = this;
      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })

    },
    methods: {//执行的方法

      searchSubmit() {//搜索
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
      addTableData() {
        this.selectData = {};
        this.formTitle = '添加';
        this.basicType = true;
      },
      //父级关闭
      closeFun(data) {
        var that = this;
        if (data) {//添加修改 刷新表单
          that.$refs.wzTbale.tableLoadData();
        }
        that.basicType = false;
      }
    },
    watch: {//监听

    },
    props: {//接收来自父组件的数据

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>

<style lang="less">
  ._wz_place {
    display: flex;
    flex-direction: column;


  }
</style>
